<template>
  <div class="table">
    <el-table
      :data="tableData"
      :loading="loading"
      @selection-change="handleSelectionChange"
      style="width: 100%"
      :header-cell-style="{
        background: '#F1F1F1',
        'font-size': '14px',
        'font-weight': 600,
        color: '#333333',
      }"
      :cell-style="{
        'font-size': '14px',
        'font-weight': 400,
        color: '#333333',
      }"
    >
      <el-table-column type="selection" width="55" fixed="left" />
      <el-table-column label="序号" min-width="60" fixed="left">
        <template #default="scope">
          {{ (scope.$index + 1).toString().padStart(2, "0") }}
        </template>
      </el-table-column>
      <el-table-column prop="vendorId" label="设备编号" min-width="180" />
      <el-table-column prop="name" label="设备名称" min-width="140" />
      <el-table-column prop="vendor" label="设备厂家" min-width="240" />
      <el-table-column label="诱导级别" min-width="80">
        <template #default="scope">
          {{ scope.row.level === 1 ? "一级" : scope.row.level === 2 ? "二级" : "三级" }}
        </template>
      </el-table-column>
      <el-table-column prop="screenSize" label="尺寸屏幕" min-width="100">
        <template #default="scope">
          {{ scope.row.width }}*{{ scope.row.height }}
        </template>
      </el-table-column>
      <el-table-column label="分频率" min-width="70">
        <template #default="scope">
          {{
            scope.row.rp === 2
              ? "P2"
              : scope.row.rp === 4
              ? "P4"
              : scope.row.rp === 6
              ? "P6"
              : scope.row.rp === 8
              ? "P8"
              : "P10"
          }}
        </template>
      </el-table-column>
      <el-table-column prop="netPattern" label="联网模式" min-width="80">
        <template #default="scope">
          {{ scope.row.netPattern === 1 ? "SIM" : "宽带" }}
        </template>
      </el-table-column>
      <el-table-column prop="address" label="具体位置" min-width="220" />
      <el-table-column label="使用状态" min-width="80">
        <template #default="scope">
          {{
            scope.row.status === 1
              ? "使用中"
              : scope.row.status === 2
              ? "未投产"
              : scope.row.status === 3
              ? "维修中"
              : scope.row.status === 4
              ? "已报废"
              : "-"
          }}
        </template>
      </el-table-column>
      <el-table-column label="运行状态" min-width="80">
        <template #default="scope">
          {{
            scope.row.runStatus === 0 ? "离线" : scope.row.runStatus === 1 ? "在线" : "-"
          }}
        </template>
      </el-table-column>
      <el-table-column label="最后心跳时间" min-width="200">
        <template #default="scope">
          <span v-if="scope.row.heartbeatTime">
            {{ scope.row.heartbeatTime }}
          </span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" min-width="110" fixed="right">
        <template #default="scope">
          <el-button
            @click="editData(scope.row)"
            type="primary"
            size="small"
            link
            style="color: #007aff; font-size: 14px"
            >编辑</el-button
          >
          <el-button
            v-if="scope.row.status === 4"
            @click="deleteData(scope.row)"
            type="primary"
            size="small"
            link
            style="color: #007aff; font-size: 14px"
            >删除</el-button
          >
        </template>
      </el-table-column>
      <template #empty>
        <el-empty :image="imgNone" />
      </template>
    </el-table>
  </div>
</template>

<script setup>
import { reactive, ref, defineProps } from "vue";
const imgNone = new URL("@/assets/image/imgNone.png", import.meta.url).href;
const emits = defineEmits(["table"]);

const props = defineProps({
  tableData: {
    type: Object,
    default: () => {},
  },
  loading: {
    type: Boolean,
    default: false,
  },
});

// 编辑按钮
const editData = (row) => {
  row.operation = 1;
  emits("table", row);
};

// 删除按钮
const deleteData = (row) => {
  row.operation = 2;
  emits("table", row);
};

const guideIdList = ref([]);
const handleSelectionChange = (val) => {
  let row = {};
  row.operation = 3;
  guideIdList.value = val.map((proxy) => proxy.id);
  row.guideIdList = guideIdList.value;
  emits("table", row);
};
</script>

<style lang="less" scoped>
.table {
  margin-bottom: 15px;
}
</style>
